package br.com.sisdoctor.view.bean.util;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

public abstract class BeanAbstract {

	protected void addMessageINFO(String message) {
		FacesContext.getCurrentInstance().addMessage(null,
				new FacesMessage(FacesMessage.SEVERITY_INFO, message, null));
	}

	protected void addMessageERROR(String message) {
		FacesContext.getCurrentInstance().addMessage(null,
				new FacesMessage(FacesMessage.SEVERITY_ERROR, message, null));
	}

	protected String getRequestParam(String name) {
		return FacesContext.getCurrentInstance().getExternalContext()
				.getRequestParameterMap().get(name);
	}

	protected Integer getRequestIntParam(String name, Integer defaultValue) {
		try {
			return Integer.parseInt(getRequestParam(name));
		} catch (Exception e) {
			return defaultValue;
		}
	}

	protected void invalidateSession() {
		FacesContext facesContext = FacesContext.getCurrentInstance();
		HttpSession session = (HttpSession) facesContext.getExternalContext()
				.getSession(false);
		session.invalidate();
	}
	
}
